using System;
/// <summary>
/// 资源结果
/// </summary>
public abstract class AbsHFAssetRequest : IHFRecycle,IHFRecycleEventHandler
{
    /// <summary>
    /// 资源路径属性
    /// </summary>
    public HFAssetBundlePathAttribute abPathAttr { get; private set; }

    /// <summary>
    /// 任务
    /// </summary>
    public AbsHFTask task { get; private set; }

    /// <summary>
    /// 成功
    /// </summary>
    public Action<AbsHFAssetResponse, object[]> onSuccess { get; private set; }

    /// <summary>
    /// 失败
    /// </summary>
    public Action<AbsHFAssetResponse, object[]> onFailed { get; private set; }
    
    /// <summary>
    /// 取消
    /// </summary>
    public Action<AbsHFAssetResponse, object[]> onCancel { get; private set; }

  
    /// <summary>
    /// 等待下载(回调给调用者)
    /// </summary>
    public Action<AbsHFAssetResponse, object[]> onWaitDownloadCallBack { get; private set; }
    /// <summary>
    /// 进度
    /// </summary>
    public Action<AbsHFAssetResponse, object[]> onProgress { get; private set; }

    /// <summary>
    /// 额外参数
    /// </summary>
    public object[] extralArgs { get; private set; }

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="_abPathAttr">资源路径属性</param>
    /// <param name="_task">任务</param>
    /// <param name="_onSuccess">成功</param>
    /// <param name="_onFailed">失败</param>
    /// <param name="_onCancel">取消</param>
    /// <param name="_onWaitDownload">等待下载</param>
    /// <param name="_onProgress">进度</param>
    /// <param name="_extralArgs">额外参数</param>
    public AbsHFAssetRequest(HFAssetBundlePathAttribute _abPathAttr, AbsHFTask _task, 
        Action<AbsHFAssetResponse, object[]> _onSuccess,
        Action<AbsHFAssetResponse, object[]> _onFailed,
        Action<AbsHFAssetResponse, object[]> _onCancel,
        Action<AbsHFAssetResponse, object[]> _onProgress,
        Action<AbsHFAssetResponse, object[]> _onWaitDownloadCallBack,
        object[] _extralArgs)
    {
        abPathAttr = _abPathAttr;
        task = _task;
        onSuccess = _onSuccess;
        onFailed = _onFailed;
        onCancel = _onCancel;
        onWaitDownloadCallBack = _onWaitDownloadCallBack;
        onProgress = _onProgress;
        extralArgs = _extralArgs;

    }

    public event Action<IHFRecycle> OnAfterRecycleHandler;
    public event Action<IHFRecycle> OnBeforeRecycleHandler;

    /// <summary>
    /// 回收资源
    /// </summary>
    public void Recycle()
    {
        OnBeforeRecycleHandler?.Invoke(this);
        OnBeforeRecycleHandler = null;
        OnRecycle();
        abPathAttr = null;
        task = null;
        onSuccess = null;
        onFailed = null;
        onCancel = null;
       
        onProgress = null;
        extralArgs = null;
        OnAfterRecycleHandler?.Invoke(this);
        OnAfterRecycleHandler = null;
    }

    /// <summary>
    /// 回收资源
    /// </summary>
    protected virtual void OnRecycle() { }
}
